package com.mes.inventory.domain;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.context.annotation.Lazy;

import com.mes.basicdata.domain.Part;
import com.mes.common.domain.BasicModel;

/**
 * <p>
 * Material实体，代表物料。 每一个物料进入系统都有条码标识
 * </p>
 * 
 */
@Entity()
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true)
@Table(name = "M_MATERIAL")
@BatchSize(size = 30)
@Lazy(value = true)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)

public class Material extends BasicModel {

	// 物料唯一号
	@Id
	@GenericGenerator(name = "uniqueId", strategy = "assigned")
	@Column(name = "MATERIALUSN", scale = 0)
	private String uniqueId;

	/**
	 * 该物料属于那个主物料 复杂对象映射--Part
	 */
	@Column(name = "PART_NUMBER")
	protected String partUid;
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
	@JoinColumn(name = "PART_NUMBER", insertable = false, updatable = false)
	protected Part part;

	// 对应物料的图号
	@Column(name = "PART_DRAWINGID")
	protected String partDrawingId;
	// 对应物料的名称
	@Column(name = "PART_NAME")
	protected String partName;
	// 对应物料的版次
	@Column(name = "PART_VERSIONID")
	protected String partVersionId;
	// 对应物料的规格
	@Column(name = "PART_DESCRIPTION")
	protected String partDescription;
	// 对应物料的规格,用于区分 是工具、在制品、产成品
	@Column(name = "MATERIAL_TYPE")
	protected String materialType;
	
	@Column(name = "BATCHNUM")
	protected String batchNum;

	/**
	 * 本批物料上的印记号 主物料号加上印记号就能够唯一确定一项物料
	 */
	@Column(name = "SN")
	protected String sn;
	/**
	 * 条码并不唯一标识一个物料 一个物料由在制转向成品后，条码标签和stampSn并不发生变化 条码可以多次打印
	 */
	@Column(name = "BARCODE")
	protected String barCode;

	/**
	 * 条码打印次数 以便于用户在条码损坏后重新打印 打印次数可以融入条码编号
	 */
	@Column(name = "ISPRINT")
	protected Integer printCount;

	/**
	 * 条码标签打印时间，可以多次打印，记录当前时间
	 */
	@Column(name = "PRINTDATE")
	protected Date printTime;
	
	@Column(name = "MATERIALSTATE")
	protected Integer materialState;

	// 以下为库房中必须具有的三期检查
	// 失效期
	@Column(name = "INVALIDDATE")
	protected Date invalidDate;
	// 复检日期，过此日期必须由检验重新进行鉴定
	@Column(name = "CHECKUP_DATE")
	protected Date checkupDate;
	// 维护日期，过此日期必须重新进行维护，如进行油封
	@Column(name = "MAINTENANCE_DATE")
	protected Date maintenanceDate;

	// 物料当前标识的数量
	@Column(name = "MATERIALQTY")
	protected Float materialQty;

	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.getUniqueId();
	}

	@Override
	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.setUniqueId(uuid);
	}

	public String getUniqueId() {
		return uniqueId;
	}

	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}

	public String getPartUid() {
		return partUid;
	}

	public void setPartUid(String partUid) {
		this.partUid = partUid;
	}

	public Part getPart() {
		return part;
	}

	public void setPart(Part part) {
		this.part = part;
	}

	public String getBatchNum() {
		return batchNum;
	}

	public void setBatchNum(String batchNum) {
		this.batchNum = batchNum;
	}

	public String getSn() {
		return sn;
	}

	public void setSn(String sn) {
		this.sn = sn;
	}

	public String getBarCode() {
		return barCode;
	}

	public void setBarCode(String barCode) {
		this.barCode = barCode;
	}

	public Integer getPrintCount() {
		return printCount;
	}

	public void setPrintCount(Integer printCount) {
		this.printCount = printCount;
	}

	public Date getPrintTime() {
		return printTime;
	}

	public void setPrintTime(Date printTime) {
		this.printTime = printTime;
	}

	public Integer getMaterialState() {
		return materialState;
	}

	public void setMaterialState(Integer materialState) {
		this.materialState = materialState;
	}

	public String getMaterialType() {
		return materialType;
	}

	public void setMaterialType(String materialType) {
		this.materialType = materialType;
	}

	public Date getInvalidDate() {
		return invalidDate;
	}

	public void setInvalidDate(Date invalidDate) {
		this.invalidDate = invalidDate;
	}

	public Date getCheckupDate() {
		return checkupDate;
	}

	public void setCheckupDate(Date checkupDate) {
		this.checkupDate = checkupDate;
	}

	public Date getMaintenanceDate() {
		return maintenanceDate;
	}

	public void setMaintenanceDate(Date maintenanceDate) {
		this.maintenanceDate = maintenanceDate;
	}

	public Float getMaterialQty() {
		return materialQty;
	}

	public void setMaterialQty(Float materialQty) {
		this.materialQty = materialQty;
	}

	public String getPartDrawingId() {
		return partDrawingId;
	}

	public void setPartDrawingId(String partDrawingId) {
		this.partDrawingId = partDrawingId;
	}

	public String getPartName() {
		return partName;
	}

	public void setPartName(String partName) {
		this.partName = partName;
	}

	public String getPartVersionId() {
		return partVersionId;
	}

	public void setPartVersionId(String partVersionId) {
		this.partVersionId = partVersionId;
	}

	public String getPartDescription() {
		return partDescription;
	}

	public void setPartDescription(String partDescription) {
		this.partDescription = partDescription;
	}


}